package com.hndzyu.yd.task;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.hndzyu.yd.R;
import com.hndzyu.yd.bean.Wechat;
import com.hndzyu.yd.url.Path;

import java.util.List;

/**
 * Created by zz9527 on 2018/10/22.
 */
public class FollowAdapter extends BaseAdapter{
    private final LayoutInflater inflater;
    private Context mContext;
    private List<Wechat.DataBean> list;

    public FollowAdapter(List<Wechat.DataBean> list, Context context) {
        this.list = list;
        this.mContext = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_lv_follow, null);
            holder = new ViewHolder();
            holder.img = convertView.findViewById(R.id.iv_follow);
            holder.title = convertView.findViewById(R.id.tv_follow_title);
            holder.point = convertView.findViewById(R.id.tv_follow_point);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Wechat.DataBean bean = list.get(i);
        RequestOptions requestOptions = RequestOptions.circleCropTransform();
        Glide.with(mContext).load(Path.img(bean.getHead())).apply(requestOptions).into(holder.img);
        holder.title.setText(bean.getName());
        holder.point.setText("+"+bean.getMax()+"元");
        return convertView;
    }

    private static class ViewHolder {
        ImageView img;

        TextView title;

        TextView point;

    }
}
